#include"process.h"
#include<string.h>
#include<unistd.h>

#define LENGHT 101
#define LABKE '#'



void FlushProcess(double target,double current)
{
    //step0:
	const static char* sym="|/-\\";
	 static int index=0;
	const int len=strlen(sym);
	//step1,更新进度
	double rate=(current / target)*100.0;
	//step2,整数个进度递增，刷新一个#
	int cnt=(int)rate;
	//step3,构建缓冲区
	char bar[LENGHT];
	memset(bar,0,sizeof(bar));
	for(int i=0;i<cnt;i++)
	{
		bar[i]=LABKE;
	}
	//step4,更新
	printf("[%-100s] %.1lf%% %c\r",bar,rate,sym[index++]);
	index%=len;
	fflush(stdout);
    //step:处理更新到100%
	if(rate>=100.0)
	printf("\n");
}

void Process()
{
	const char* syum="|/-\\";
	int s_len=strlen(syum);
   char bar[LENGHT];
   memset(bar,'\0',sizeof(bar));
   int cnt=0;
   while(cnt<=100)
   {
		printf("[%-100s]%d%% %c\r",bar,cnt,syum[cnt%s_len]);
		fflush(stdout);
		bar[cnt++]=LABKE;
		usleep(100000);
   }
   printf("\n");
}


	

